package cn.lingyangwl.agile.model;

import cn.lingyangwl.framework.tool.core.CollectionUtils;
import cn.lingyangwl.framework.tool.core.tree.TreeNode;
import cn.lingyangwl.framework.tool.core.tree.TreeUtils;
import lombok.Getter;
import lombok.Setter;

import java.util.Collections;
import java.util.List;

/**
 * 通过继承该类的子类可以直接使用 {@link TreeUtils} 工具类
 * @author shenguangyang
 */
@Getter
@Setter
public abstract class BaseTree<ID, T> implements TreeNode<ID, T> {
    protected List<T> children;

    /**
     * 排序号（升序）
     */
    protected Integer sortNo;

    /**
     * 是否被禁用
     */
    protected Boolean disabled = false;

    /**
     * 所有父级编号
     */
    protected String parentIds;

    /**
     * 是否为叶子节点(最末级)
     */
    protected String treeLeaf;

    /**
     * 层次级别
     */
    protected Integer treeLevel;

    /**
     * 全节点名
     */
    protected String treeNames;

    public interface TreeLeaf {
        String YES = "1";
        String NO = "0";
    }

    @Override
    public List<T> children() {
        return this.children;
    }

    @Override
    public void children(List<T> children) {
        this.children = CollectionUtils.isEmpty(children) ? Collections.emptyList() : children;
    }

    @Override
    public Integer sortNo() {
        return this.sortNo;
    }

    @Override
    public void treeLeaf(Boolean treeLeaf) {
        this.setTreeLeaf(treeLeaf ? TreeLeaf.YES : TreeLeaf.NO);
    }

    @Override
    public void treeLevel(Integer treeLevel) {
        setTreeLevel(treeLevel);
    }

    @Override
    public void treeNames(String names) {
        setTreeNames(names);
    }

    @Override
    public void treeParentIds(String parentIds) {
        setParentIds(parentIds);
    }
}
